/*
 * stocklistseries.h
 *
 *  Created on: 27/mag/2014
 *      Author: PegorarS
 */

#ifndef STOCKLISTSERIES_H_
#define STOCKLISTSERIES_H_

#include "stockexchange.h"
#include "order.h"
#include "patterns.h"
#include <map>

using namespace std;

namespace NS_STOCKEXCHANGE{

	class StockDataSeries{
	public:
		StockDataSeries(Ticker _stockName, StockDbBrokerI *_dbReader);
		StockDataSeries(Ticker _stockName, Date _begin, Date _end, StockDbBrokerI *_dbReader);
		~StockDataSeries();

		bool IsFirst() const;
		bool IsLast() const;
		StockData & Begin();
		StockData & End();
		StockData & Next();
		StockData & Prev();

		StockData & operator[](int i){
			return currData[i];
		}

	private:
		StockDbBrokerI *dbReader;

		Ticker stockName;
		Date begin;
		Date end;
		vector<StockData> graph;
		vector<StockData>::iterator currData;
	};

	class StockListSeries : public Publisher<Date>{
	public:
		static StockListSeries *Create(StockDbBrokerI *_dbReader);
		static void Destroy(StockListSeries *sls);

		virtual void Publish(Date &lastDate);

		StockDataSeries *LoadSeries(Ticker stockName, Date begin, Date end);
		StockDataSeries *LoadSeries(Ticker stockName, int nPastDays);
		bool NewData() const;
		bool Match(Order *ord, Date orderDate) const;

	private:
		StockListSeries(StockDbBrokerI *_dbReader);
		virtual ~StockListSeries();

		StockDbBrokerI *dbReader;
		Date lastDate;

		struct SeriesRange{
			Date begin;
			Date end;
		};
		map<Ticker, SeriesRange> stockList;

		static int nInstances;
	};
}


#endif /* STOCKLISTSERIES_H_ */
